﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyAlbum.Model;

namespace MyAlbum.Services
{
    public static class UserExtensions
    {
       
        public static bool ShowOnlyVisibleEntries(this IUser user)
        {
            return !user.IsInRole(RolesManager.AdminRoles) &&
                    !user.IsInRole(RolesManager.PowerUser);

        }

        public static bool AllowActions(this IUser user)
        {
            return user.IsInRole(RolesManager.AdminRoles);
        }

        public static bool AllowAddEntries(this IUser user)
        {
            return user.IsInRole(RolesManager.AddEntriesRoles);
        }

        public static bool AllowAdd(this IUser user)
        {
            return user.IsInRole(RolesManager.AdminRoles);
        }

        private static bool IsInRole(IUser user, string roles)
        {
            var result = false;
            foreach (var role in roles.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (user.IsInRole(role))
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
    }
}
